//
//  BCRNModule.h
//  BCFoundation
//
//  Created by Basic on 2021/4/19.
//  ReactNative 模块协议

#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

///重定义
#undef RCT_EXPORT_MODULE

#define RCT_EXPORT_MODULE(js_name)          \
  RCT_EXTERN void RCTRegisterModule(Class); \
  +(NSString *)moduleName                   \
  {                                         \
    return @ #js_name;                      \
  }                                         \
  +(void)load                               \
  {                                         \
    CFAbsoluteTime stime = CFAbsoluteTimeGetCurrent();\
    RCTRegisterModule(self);                \
    CFAbsoluteTime etime = CFAbsoluteTimeGetCurrent();\
    NSLog(@"%@ eta:%f",[self class],(etime-stime)*1000);\
  }

///主线程安全调用
#define rnsafe_dispatch_async(block) { \
    if(block){\
        if ([NSThread isMainThread]) {\
            block();\
        } else {\
            dispatch_async(dispatch_get_main_queue(), block);\
        }\
    }\
}\


@protocol BCRNModule <NSObject>
@optional
///模块初始化
- (void)setupModule;
@end


NS_ASSUME_NONNULL_END
